using Magiq.Delete;
using Magiq.Insert;
using Magiq.Query;
using Magiq.Support;
using Magiq.Update;

namespace Magiq.Objects
{
    public class MagiqToObjects : IMagiqProvider
    {
        private readonly EnumerableSourceFinder enumerableSourceFinder = new EnumerableSourceFinder();

        public IUpdateStrategy GetUpdateStrategy<T>(IUpdate<T> update) where T : class
        {
            return new UpdateStrategy<T>(update);
        }

        public IDeleteStrategy GetDeleteStrategy<T>(IDelete<T> delete) where T : class
        {
            return new DeleteStrategy<T>(delete);
        }

        public IInsertStrategy GetInsertStrategy<TSource, TDestination, TNew>( IInsert<TSource, TDestination, TNew> insert) where TDestination : class where TNew : class, TDestination, new()
        {
            return new InsertStrategy<TSource, TDestination, TNew>(insert);
        }

        public IInsertDestination<TNew> GetInsertDestination<TSource, TDestination, TNew>( IInsert<TSource, TDestination, TNew> insertDestinationDefinition)
            where TNew : class, TDestination, new()
            where TDestination : class
        {
            return new ListInsertDestination<TNew>(enumerableSourceFinder.FindSourceOf(insertDestinationDefinition.Destination));
        }

        public IQueryStrategy<T> GetQueryStrategy<T>(IQuery<T> query) where T : class
        {
            return new QueryStrategy<T>(query);
        }
    }
}